<?php

//购物车列表页控制器
class ShoplistController extends Controller{
	
	//首页
	public function index(){
		
		$shop=Cart::getGoods();
		$zong=Cart::getAllData();
		$this->assign('zong',$zong);
		if($shop){
			$str=array();
		    foreach ($shop as $k => $v) {
		    	foreach ($v['options'] as $kk => $vv) {
		    		   $kk=M()->join("__attr__ a JOIN __goods_attr__ ga ON a.taid=ga.taid")->where("gtid={$vv}")->getField('taname',true);
					   $kk=implode($kk);
					   $da=K('Goodsattr')->where("gtid={$vv}")->getField('gtvalue',true);
					   $shop[$k]['attrSpec'][$kk]=$da;
		    	}
		    }
			$this->assign('shop',$shop);
		}
		$this->display();
	}
	
	public function addShop(){
		if(IS_AJAX){
			$data=Q('post.');
			$shoplist=Cart::getGoods();
			p($shoplist);
			$dingdan=Cart::getOrderId();
			$total = Cart::getTotalPrice();
			$uid=$_SESSION['uid'];
			//调用模型方法添加到订单表
			$ding=array(
			    'number' =>$dingdan,
				'consignee' =>$data['name'],
				'address' =>$data['dj'].','.$data['dizhi'],
				'mobile' =>$data['dianhua'],
				'total' =>$total,
				'time' =>time(),
				'uid' =>$uid,
			);
			$slid=K('Shoplist')->shopAdd($ding);
			//添加订单列表
			foreach ($shoplist as $k => $v) {
				$arr=array(
				   'quantity' =>$v['num'],
				   'subtotal' =>$v['total'],
				   'gid' =>$v['id'],
				   'slid' =>$slid,
				   'options' =>implode(',', $v['options']),
				);
				K('Shopcat')->add($arr);
			}
			Cart::delAll();
			$asd=1;
			$this->ajax($asd);
		}
		
		
	}
	
	
	
	
}


?>